package com.tan.core.utils;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;

import java.time.LocalDateTime;


public class IdGenerate {

    private final static Long WORKER_ID = 1L;

    private final static Long DATA_CENTER_ID = 1L;


    public static String getId() {
        Snowflake snowflake = IdUtil.getSnowflake(WORKER_ID, DATA_CENTER_ID);
        return snowflake.nextIdStr();
    }


    public static String createBusinessNo(String codeHeader) {
        return codeHeader.concat(getTime()).concat(getId().substring(6));
    }


    /**
     * 简化的UUID，去掉了横线
     *
     * @return 简化的UUID，去掉了横线
     */
    public static String simpleUUID() {
        return UUID.randomUUID().toString(true);
    }

    /**
     * 获取随机UUID，使用性能更好的ThreadLocalRandom生成UUID
     *
     * @return 随机UUID
     */
    public static String fastUUID() {
        return UUID.fastUUID().toString();
    }

    /**
     * 简化的UUID，去掉了横线，使用性能更好的ThreadLocalRandom生成UUID
     *
     * @return 简化的UUID，去掉了横线
     */
    public static String fastSimpleUUID() {
        return UUID.fastUUID().toString(true);
    }

    private static String getTime() {
        return LocalDateTimeUtil.format(LocalDateTime.now(), "yyyyMMddHHmmssSSS");
    }
}
